#ifndef __LOGIC_H__
#define __LOGIC_H__

#include <cstdint>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <map>
#include <queue>
#include <functional>
#include <memory>
#include <string>

#include "Session.h"

using FunCallBack = std::function<void(std::shared_ptr<Session>, const uint32_t &msg_id, const std::string &msg_data)>;

class Logic
{
public:
    Logic();
    void PostMsgToQueue(std::shared_ptr<LogicNode> msg);
    void SetServer(std::shared_ptr<Server> server) { _server = server; }
    ~Logic();

private:
    void _Process();
    void _InitCallback();

private:
    std::thread _worker_thread;
    std::queue<std::shared_ptr<LogicNode>> _msg_queue;
    std::mutex _queue_mutex;
    std::condition_variable _cv;
    bool _is_stop;
    std::map<uint32_t, FunCallBack> _fun_callbacks;
    std::shared_ptr<Server> _server;
};


void LoginHandler(std::shared_ptr<Session> session, const uint32_t &msg_id, const std::string &msg_data);


#endif // !__LOGIC_H__